package com.haizhi.crm.biz.model;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhangjunfei on 2018/3/10.
 *
 * @author zhangjunfei
 * @descripe 查询图平台 关系数据
 */
@Data
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Component
public class GraphConfig {

    private List startVertexIds = new ArrayList();

    private Param param = new Param();

    @PostConstruct
    public void init() {
        this.param.getGraphDB().put("name", "crm_dev" );
        this.param.getOptions().getLimit().put("offset", 0);
        this.param.getOptions().getLimit().put("count", 100);
    }

    public void addVertex(String id) {
        startVertexIds.add(id);
    }

    public void addVertex(String schema, String id) {
        startVertexIds.add(schema + "/" + id);
    }

    public void addNode(String node) {
        this.param.getOptions().getNodes().add(node);
    }

    public void addEdge(String edge) {
        this.param.getOptions().getEdges().add(edge);
    }

    public void addEdgeList(List<String> edgeList) {
        this.param.getOptions().getEdges().addAll(edgeList);
    }

    @Data
    private class Param {
        @JSONField(name = "graph_db" )
        private Map graphDB = new HashMap();

        private Options options = new Options();
    }

    @Data
    private class Options {
        private String direction = "ANY";
        private Integer maxDepth = 1;
        private List<String> edges = new ArrayList();
        private List<String> nodes = new ArrayList();
        private Map<String, Integer> limit = new HashMap();
    }
}
